{extend name="adminblue/base" /}
{block name="resources"/}
<style>
.mod-table{padding:15px;}
.table-class tbody td a{margin-left:8px !important;}
</style>
{/block}
{block name="main"}
<div class="space-10"></div>
<div class="ncsc-form-goods">
	{include file="adminblue/Express/expressTitle"}
	<!-- 基础设置 -->
	<div class="mod-table">
	<div class="mod-table-head">
		<table class="mytable">
			<tr>
				<td width="20%" style="text-align: left;">
					<button style="margin:0 5px 0 0 !important;" class="btn-common-delete btn-small" onclick="batchDelete()">批量删除</button>
					<button style="margin:0 5px 0 0 !important;" class="btn-common btn-small" onclick="location.href='{:__URL('ADMIN_MAIN/shop/addpickuppoint')}';">添加门店</button>
				</td>
				<td width="20%">
					<input type="text" id = 'search_text' placeholder="请输入门店名称" class="input-common"/>
					<input type="button" onclick="searchData()" value="搜索" class="btn-common" />
				</td>
			</tr>
		</table>
		<div class="con style0list">

			<table class="table-class">
			<colgroup>
				<col style="width: 2%">
				<col style="width: 18%;">
				<col style="width: 18%;">
				<col style="width: 18%;">
				<col style="width: 18%;">
				<col style="width: 16%;">
				<col style="width: 10%;">
			</colgroup>
			<thead>
				<tr align="center">
					<th><i class="checkbox-common"><input id="ckall" type="checkbox" onClick="CheckAll(this)"></i></th>
					<th align="left">门店名称</th>
					<th align="left">地址</th>
					<th>联系人</th>
					<th>联系电话</th>
					<th>发布时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		</div>
	</div>
</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/shop/pickuppointlist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			//console.log(data);
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data['data'][i]['id']+'"></i></td>';
					html += '<td align="left">' + data["data"][i]["name"]+ '</td>';
					html += '<td align="left">'+ data["data"][i]["province_name"]+ '/'+ data["data"][i]["city_name"]+ '/' + data["data"][i]["dictrict_name"]+ '/'+ data["data"][i]["address"]+'</td>';
					
					html += '<td>' + data["data"][i]["contact"]+ '</td>';
					html += '<td>'+data["data"][i]["phone"]+'</td>'
					html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"])+ '</td>';
					html += '<td>';
						html += '<a href="'+__URL('ADMIN_MAIN/shop/updatepickuppoint?id='+ data['data'][i]['id'])+'">修改</a>';
						html += '<a onclick="deletepickupPoint('+data['data'][i]['id']+')">删除</a>';
					html += '</td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无自提点</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}	

function batchDelete() {
	var pickupPoint_id= new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			pickupPoint_id.push($(this).val());
		}
	});
	if(pickupPoint_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deletepickupPoint(pickupPoint_id);
}
var flag = false;
//删除
function deletepickupPoint(pickupPoint_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				if(!flag){
					flag = true;
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/shop/deletepickuppoint')}",
						data : {
							"pickupPoint_id" : pickupPoint_id.toString()
						},
						dataType : "json",
						success : function(data) {
							if (data["code"] > 0) {
								showTip(data["message"],'success');
								window.location.href=__URL("ADMIN_MAIN/shop/pickuppointlist");
							}else{
								showTip(data["message"],'error');
								flag = false;
							}
						}
					})
				}
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			}
		},
	contentText:"是否删除该自提点？",
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
	if(checked) $(".table-class tbody input[type = 'checkbox']").parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").parent().removeClass("selected");
}

function searchData(){
	LoadingInfo(1);
}
</script>
{/block}